package xyz.xpman.prisonerfitness.entity;

import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;

import xyz.xpman.prisonerfitness.util.JsonUtil;

public class Guide extends Record {
    public static final String IMG = "img";
    public static final String TITLE = "title";
    public static final String DESCRIPTION = "description";

    public static final String VIDEO = "video";


    public String getTitle() {
        return getStr(TITLE);
    }

    public String getDescription() {
        return getStr(DESCRIPTION);
    }


    public boolean hasImg() {
        final String[] img = getImg();

        return null != img && img.length > 0;
    }

    public String[] getImg() {
        return get(IMG);
    }


    public boolean hasVideo() {
        final String video = getVideo();

        return null != video && !video.isEmpty();
    }

    public String getVideo() {
        return get(VIDEO);
    }


    public static Guide byJson(@NotNull JSONObject json) {
        Guide guide = new Guide();

        try {
            guide.set(TITLE, json.getString(TITLE));
            guide.set(DESCRIPTION, json.getString(DESCRIPTION));
            guide.set(IMG, JsonUtil.toStringArray(json.getJSONArray(IMG)));

            guide.set(VIDEO, json.getString(VIDEO));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return guide;
    }

}
